<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require dirname(__FILE__).'/pc_controller.php';

require_once dirname(__FILE__).'/menu.php';

class K_360_recieve_customer extends PC_controller {

    public function __construct(){
        parent::__construct();
        $this->load->model('K360receivecustomer','m_customer');
    }

    public function index(){
        $data = parent::index();

        global $g_360_gift;
        $data['game_gift'] = array4js($g_360_gift);

        $this->load->view('admin/k_360_recieve_customer',$data);
    }

    public function getCustomerList(){

        $assist['where'] = getFilter($this->input->post(),K360receivecustomer::$searchField);
        $assist['like'] = getFilter($this->input->post(),K360receivecustomer::$likeField);
        $assist['sort'] = getSort($this->input->post(),K360receivecustomer::$sortField);
        $assist['pagination'] = getPagination($this->input->post());

        list($list,$count) = $this->m_customer->getCustomerListSection($assist);

        foreach ($list as $key => $value) {
        	$list[$key]['customer_passport_picture_info_path'] = UPLOAD_URL_ORIGIN.$list[$key]['customer_passport_picture_info_path'];
        	$list[$key]['customer_passport_picture_visa_path'] = UPLOAD_URL_ORIGIN.$list[$key]['customer_passport_picture_visa_path'];
        }

        $this->response->setSuccess();
        $this->response->setItems($list);
        $this->response->setTotalCount($count);
        $this->response->responseExit();
    }


    public function exportCustomerList() {
        @set_time_limit(0);
        @ini_set('memory_limit', '2048M');


        $assist['where'] = getFilter($this->input->get(),K360receivecustomer::$searchField);
        $assist['like'] = getFilter($this->input->get(),K360receivecustomer::$likeField);
        $assist['sort'] = getSort($this->input->get(),K360receivecustomer::$sortField);

        $this->load->library('excel');
        $this->excel->init('北京现代游戏用户_'.date('YmdH').'.xls');
        $this->excel->addSheet('北京现代游戏用户');
        $this->excel->addTitle(array(
            array('content'=>'ID'),
            array('content'=>'姓名'),
            array('content'=>'手机号'),
            array('content'=>'收货地址'),
            array('content'=>'微信号'),
            array('content'=>'公司名称'),
            array('content'=>'公司地址'),
            array('content'=>'护照主页信息照片'),
            array('content'=>'护照签注信息照片'),
            array('content'=>'申请时间'),
        ));
        
        list($list,$count) = $this->m_customer->getCustomerListSection($assist);


        global $g_360_gift;

        foreach ($list as $key => $value) {
            $gift_info = array();

            $this->excel->addRow(array(
                array('content' => $value['customer_id']),
                array('content' => $value['customer_name']),
                array('content' => $value['customer_phone']),
                array('content' => $value['customer_address']),
                array('content' => $value['customer_weixin']),
                array('content' => $value['customer_company_name']),
                array('content' => $value['customer_company_address']),
                array('content' => UPLOAD_URL_ORIGIN.$value['customer_passport_picture_info_path']),
                array('content' => UPLOAD_URL_ORIGIN.$value['customer_passport_picture_visa_path']),
                array('content' => $value['customer_time_create']),
            ));
        }

        $this->excel->freezePanes(1,0);
        $this->excel->generate();
    }

    public function disableCustomer() {
        $this->validate->setRule('customer_id','integer');
        $this->validate->setRule('customer_id','message',$this->lang->line('error_parameter'));
        if(!$this->validate->run($this->input->post())){
            $this->response->setDetail($this->validate->getMessage());
            $this->response->responseExit();
        }
        $info = $this->validate->getResult();

        $info['customer_status'] = STATUS_DELETE;
        $this->m_customer->editCustomer($info);

        $this->response->setSuccess();
        $this->response->setDetail('更新成功!');
        $this->response->responseExit();
    }

    public function enableCustomer() {
        $this->validate->setRule('customer_id','integer');
        $this->validate->setRule('customer_id','message',$this->lang->line('error_parameter'));
        if(!$this->validate->run($this->input->post())){
            $this->response->setDetail($this->validate->getMessage());
            $this->response->responseExit();
        }
        $info = $this->validate->getResult();

        $info['customer_status'] = STATUS_DISABLE;
        $this->m_customer->editCustomer($info);

        $this->response->setSuccess();
        $this->response->setDetail('更新成功!');
        $this->response->responseExit();
    }
}
/* End of file customer.php */
/* Location: ./application/controllers/customer.php */